// pages/report/report.js
import { Report } from '../../../models/report'
const reportModel = new Report()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: '',
    id: '',
    type: '',
    title: '',
    selectedList: [],
    reportReason: [{
      "desc": "无法联系到招聘方",
      "reasons": ["非招聘方接听", "一直无人接听", "空号"]
    }, {
      "desc": "职位内容和企业问题",
      "reasons": ["地址虚假", "薪资虚假", "涉黄非法", "招聘职位虚假", "非招聘信息", "变相收费", "公司不存在"]
    }]
  },

  onReady () {
  },

  onLoad (option) {
    console.log(option)
    this.setData({
      id: option.id,
      type: option.type,
      title: option.title
    })
  },

  report () {
    if (!this.data.selected) {
      wx.showToast({
        title: '请选择举报理由',
        icon: 'none'
      })
      return
    }
    reportModel.report({
      reportId: this.data.id,
      reportReason: this.data.selectedList.join(),
      reportTitle: this.data.title,
      reportType: this.data.type,
      contactPhone: this.data.phone
    }, res => {
      wx.showToast({
        title: '举报成功'
      })
      wx.requestSubscribeMessage({
        tmplIds: ['kVT-oyFHirjOPD_5SyimoxorZluFsZObjhhx6L0KMAY', 'PbmE0p7hgtUXlZcUEgR_qBcP3tMhbe1-_wKNw7CkoZY'],
        complete (res) {
          wx.navigateBack({
            delta: 1
          })
        }
      })
    })
  },

  onOptionTap(e) {
    const key = e.currentTarget.dataset.item
    const dataList = this.data.selectedList
    if (dataList.indexOf(key) > -1) {
      dataList.splice(dataList.indexOf(key), 1)
    } else {
      dataList.unshift(key)
    }
    this.setData({
      selected: dataList.join(','),
      selectedList: dataList
    })
  },

})
